package logic

import (
	"context"
	"product/productrpc/productrpc"

	"product/api/internal/svc"
	"product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdateLogic {
	return &ProductUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductUpdateLogic) ProductUpdate(req *types.ProductUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	productupdate, err := l.svcCtx.ProductRpc.ProductUpdate(l.ctx, &productrpc.ProductUpdateRequest{
		Title:        req.Title,
		UserId:       req.UserId,
		Price:        float32(req.Price),
		BrowseNumber: req.BrowseNumber,
		Image:        req.Image,
		ClassId:      req.ClassId,
		ProductId:    req.ProductId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品修改成功",
		Code:    200,
		Data:    productupdate,
	}, nil
}
